package com.aibaixun.web.controller.system;

import cn.hutool.json.JSONUtil;
import com.aibaixun.common.core.domain.R;
import com.aibaixun.system.domain.PostureDevice;
import com.aibaixun.system.domain.dto.DicmAddressData;
import com.aibaixun.system.domain.dto.IndexStatisticsDto;
import com.aibaixun.system.domain.vo.*;
import com.aibaixun.system.service.*;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 首页统计模块
 *
 * @author zhangyh
 * @date 2023-09-01
 **/
@RestController
@RequestMapping("/index/statistics" )
public class IndexStatisticsController {
    private static final Logger logger = LoggerFactory.getLogger(IndexStatisticsController.class);

    @Autowired
    private IndexStatisticsService indexStatisticsService;

    @Autowired
    private LkCentralfaultOrderViewService lkCentralfaultOrderViewService;

    @Autowired
    private LkMqttDataService lkMqttDataService;

    /**
     * 获取电力、冷量统计
     * @return
     */
    @ApiOperation(value = "获取电力、冷量、机柜统计")
    @PostMapping("/power/cabinet")
    public R<PowerAndCabinetStatisticsVo> getPowerAndCold(@RequestBody @Validated IndexStatisticsDto dto){
        return indexStatisticsService.getPowerAndCabinet(dto);
    }

    /**
     * 获取告警统计
     * @return
     */
    @ApiOperation(value = "获取告警统计")
    @PostMapping("/alarm")
    public R<AlarmStatisticsVo> getAlarm(@RequestBody @Validated IndexStatisticsDto dto){
        return indexStatisticsService.getAlarm(dto);
    }

    @ApiOperation("告警列表")
    @GetMapping("/alarm/list")
    public R queryAlarmList(){
        List<QueryAlarmVo> alarmList = indexStatisticsService.queryAlarmList();
        logger.info("获取告警列表返回结果:{}"+ JSONUtil.parse(alarmList));
        return R.ok(alarmList);
    }

    /**
     * 获取工单统计
     * @return
     */
    @ApiOperation(value = "获取工单统计")
    @PostMapping("/work/order")
    public R<WorkOrderStatisticsVo> getWorkOrder(@RequestBody @Validated IndexStatisticsDto dto){
//        return indexStatisticsService.getWorkOrder(dto);
        return lkCentralfaultOrderViewService.getWorkOrder(dto);
    }

    /**
     * 获取能效统计
     * @return
     */
    @ApiOperation(value = "获取能效统计")
    @PostMapping("/energy/pue")
    public R<QueryEnergyEfficiencyVo> getEnergyPue(@RequestBody @Validated IndexStatisticsDto dto){
//        return indexStatisticsService.getEnergyPue(dto);
        return lkMqttDataService.getEnergyPue(dto);
    }

    @ApiOperation(value = "查询小时能效数据")
    @GetMapping("/query/energy")
    public R queryEnergyInfo(){
        List<DicmAddressData> list = lkMqttDataService.queryEnergyInfo();
        return R.ok(list);
    }

    /**
     * 获取小时PUE前五统计
     * @return
     */
    @ApiOperation(value = "获取小时PUE前五统计")
    @PostMapping("/top/pue")
    public R<List<TopPueStatisticsVo>> getTopPue(@RequestBody @Validated IndexStatisticsDto dto){
        return indexStatisticsService.getTopPue(dto);
    }

    /**
     * 获取大屏展示工单列表
     * @return
     */
    @ApiOperation("大屏获取工单详情")
    @GetMapping("/query/WorkOrder/list")
    public R queryWorkOrderList(){
        List<QueryWordOrderVo> wordOrderList = lkCentralfaultOrderViewService.queryWorkOrderList();
        return R.ok(wordOrderList);
    }

    @ApiOperation("统计机柜使用情况")
    @PostMapping("/cabinet")
    public R getCabinetTotal(@RequestBody IndexStatisticsDto dto){
        CabinetUsageSituationVo vo = lkMqttDataService.getCabinetTotal(dto);
        return R.ok(vo);
    }



}
